/*
 * MainApp.java
 */
package ATBMS.control;

import ATBMS.view.AboutDialog;

import ATBMS.view.login.LoginDialog;
import ATBMS.view.login.LoginViewInterface;
import javax.swing.JDialog;
import javax.swing.JFrame;
import org.jdesktop.application.Action;
import org.jdesktop.application.Application;
import org.jdesktop.application.SingleFrameApplication;

/**
 * The main class of the application.
 */
public class MainApp extends SingleFrameApplication {

    private LoginViewInterface lv;

    /**
     * At startup create and show the main frame of the application.
     * Create Login Control and LoginDialog
     */
    @Override
    protected void startup() {
        ShowLogin();
    }

    public void ShowLogin() {
        if (lv == null) {
            LoginControl wc = new LoginControl();
            lv = new LoginDialog(getMainFrame(), wc);
            wc.setLoginView(lv);
        }
        lv.doModal();
    }

    /**
     * This method is to initialize the specified window by injecting resources.
     * Windows shown in our application come fully initialized from the GUI
     * builder, so this additional configuration is not needed.
     */
    @Override
    protected void configureWindow(java.awt.Window root) {
    }

    /**
     * A convenient static getter for the application instance.
     * @return the instance of MainApp
     */
    public static MainApp getApplication() {
        return Application.getInstance(MainApp.class);
    }

    /**
     * Show About Dialog     *
     */
    @Action
    public void about() {
        if (aboutBox == null) {
            JFrame mainFrame = getApplication().getMainFrame();
            aboutBox = new AboutDialog(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        MainApp.getApplication().show(aboutBox);
    }

    /**
     * MainApp method launching the application.
     */
    public static void main(String[] args) {
        launch(MainApp.class, args);
    }
    /**
     * aboutDialog Instance
     */
    private JDialog aboutBox;
}
